var app = getApp()
Page({
  data: {
    current: 'tab1',
    current_scroll: 'tab1',
    tab1:true,
    tab2:false,
    user_id:'',
    messages:[]
  },

  onLoad:function(){
    this.setData({
      user_id:wx.getStorageSync('uid')
    })
    this.message(this.data.user_id,1)

  },

  handleChange({ detail }) {
    var index = detail.key
    this.setData({
      current: detail.key
    });
    if (index == 'tab1') {
      this.setData({
        tab1: true,
        tab2: false
      })
      this.message(this.data.user_id, 1)
    }
    else if (index == 'tab2') {
      this.setData({
        tab1: false,
        tab2: true
      })
      this.message(this.data.user_id, 2)
    }
  },
  message(user_id , type)
  {
    let that = this
    wx.request({
      url: app.url + 'weiapp/Api/getMessage',
      data:{
        uid:user_id,
        type:type
      },
      success:function(res)
      {
        that.setData({
          messages:res.data.data
        })
      }
    })
    
  }
});